import 'package:flutter/material.dart';
import 'dart:math' as math;

/// 手绘导航栏图标类型枚举
enum HandDrawnNavIconType {
  home,      // 首页
  review,    // 替换原diary
  profile,   // 替换原settings
}

/// 手绘导航栏图标绘制类
class HandDrawnNavIcon extends StatelessWidget {
  final HandDrawnNavIconType type;
  final double size;
  final Color color;

  const HandDrawnNavIcon({
    Key? key,
    required this.type,
    required this.size,
    required this.color,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      size: Size(size, size),
      painter: _HandDrawnNavIconPainter(type: type, color: color),
    );
  }
}

/// 手绘导航栏图标画笔类
class _HandDrawnNavIconPainter extends CustomPainter {
  final HandDrawnNavIconType type;
  final Color color;

  _HandDrawnNavIconPainter({
    required this.type,
    required this.color,
  });

  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()
      ..color = color
      ..style = PaintingStyle.stroke
      ..strokeWidth = 2.0
      ..strokeCap = StrokeCap.round;

    switch (type) {
      case HandDrawnNavIconType.home:
        _drawHome(canvas, size, paint);
        break;
      case HandDrawnNavIconType.review:
        _drawReview(canvas, size, paint);
        break;
      case HandDrawnNavIconType.profile:
        _drawProfile(canvas, size, paint);
        break;
    }
  }

  /// 绘制首页图标（手绘风格的房子）
  void _drawHome(Canvas canvas, Size size, Paint paint) {
    final path = Path();
    
    // 屋顶
    path.moveTo(size.width * 0.2, size.height * 0.5);
    path.lineTo(size.width * 0.5, size.height * 0.2);
    path.lineTo(size.width * 0.8, size.height * 0.5);
    
    // 房子主体
    path.moveTo(size.width * 0.3, size.height * 0.45);
    path.lineTo(size.width * 0.3, size.height * 0.8);
    path.lineTo(size.width * 0.7, size.height * 0.8);
    path.lineTo(size.width * 0.7, size.height * 0.45);
    
    // 门
    path.moveTo(size.width * 0.45, size.height * 0.8);
    path.lineTo(size.width * 0.45, size.height * 0.6);
    path.lineTo(size.width * 0.55, size.height * 0.6);
    path.lineTo(size.width * 0.55, size.height * 0.8);

    canvas.drawPath(path, paint);
  }

  /// 绘制回顾图标（类似翻开的书本）
  void _drawReview(Canvas canvas, Size size, Paint paint) {
    final path = Path();
    
    // 回顾图标：类似翻开的书本
    // 书本左页
    path.moveTo(size.width * 0.3, size.height * 0.2);
    path.lineTo(size.width * 0.3, size.height * 0.8);
    path.lineTo(size.width * 0.5, size.height * 0.7);
    path.lineTo(size.width * 0.5, size.height * 0.3);
    path.close();
    
    // 书本右页
    path.moveTo(size.width * 0.5, size.height * 0.3);
    path.lineTo(size.width * 0.5, size.height * 0.7);
    path.lineTo(size.width * 0.7, size.height * 0.8);
    path.lineTo(size.width * 0.7, size.height * 0.2);
    path.close();
    
    // 书页线条
    path.moveTo(size.width * 0.35, size.height * 0.4);
    path.lineTo(size.width * 0.45, size.height * 0.38);
    path.moveTo(size.width * 0.35, size.height * 0.5);
    path.lineTo(size.width * 0.45, size.height * 0.48);
    
    path.moveTo(size.width * 0.55, size.height * 0.38);
    path.lineTo(size.width * 0.65, size.height * 0.4);
    path.moveTo(size.width * 0.55, size.height * 0.48);
    path.lineTo(size.width * 0.65, size.height * 0.5);

    canvas.drawPath(path, paint);
  }

  /// 绘制头像轮廓
  void _drawProfile(Canvas canvas, Size size, Paint paint) {
    final path = Path();
    
    // 头像轮廓
    final center = Offset(size.width * 0.5, size.height * 0.4);
    canvas.drawCircle(center, size.width * 0.25, paint);
    
    // 身体轮廓
    path.moveTo(size.width * 0.5, size.height * 0.65);
    path.lineTo(size.width * 0.5, size.height * 0.85);
    
    // 肩膀
    path.moveTo(size.width * 0.3, size.height * 0.7);
    path.quadraticBezierTo(
      size.width * 0.5, size.height * 0.6,
      size.width * 0.7, size.height * 0.7,
    );

    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
} 